/*
 * @Author: silence
 * @Date: 2023-06-30 15:00:37
 * @LastEditors: silence silence9685@163.com
 * @LastEditTime: 2023-08-02 15:31:32
 * @Description: 首页-温度监控
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sil_base_widget_package/sil_base_widget_package.dart';

import '../../../utils/color/ColorUtils.dart';
import '../../Mine/Language/SilLocalizations/SilLocalizations.dart';
import '../../PowerStation/Controller/PowerStationController.dart';

class HomeTempMonitoringView extends StatefulWidget {
  const HomeTempMonitoringView({super.key});

  @override
  State<HomeTempMonitoringView> createState() => _HomeTempMonitoringViewState();
}

class _HomeTempMonitoringViewState extends State<HomeTempMonitoringView> {
  PowerStationController _powerStationController =
      Get.put(PowerStationController());
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(bottom: 40.w, left: 20.w, right: 20.w),
      child: contentView(),
    );
  }

  contentView() {
    return Column(
      children: [
        /// 标题
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            SilButton(
              imgPath: 'imgs/home/home_wendu.png',
              imgHeight: 25.w,
              imgWidth: 25.w,
              title: LangOf(context)?.index?.wdjk,
              titleColor: ColorUtils.color_font_main,
              fontSize: 16.sp,
              imagePosition: ImagePosition.Left,
              maxLines: 0,
            ),
            Container(),
          ],
        ),

        /// 具体信息（电池温度、逆变器温度）
        Obx(() => specailInfoView())
      ],
    );
  }

  specailInfoView() {
    List<String?> itemTitles = [];
    itemTitles.add(LangOf(context)?.index?.dcwd);
    itemTitles.add(LangOf(context)?.index?.hjwd);

    List<String?> itemValues = ['0.0', '0.0'];
    itemValues[0] = _powerStationController
        .powerStationEntity.value.bmsTemperatureStr; // 电池温度
    itemValues[1] = _powerStationController
        .powerStationEntity.value.inverterTemperatureStr; // 逆变器内部温度

    List<Widget> itemWidgets = [];
    for (var i = 0; i < itemTitles.length; i++) {
      SilText titleWidget = SilText(itemTitles[i],
          color: ColorUtils.color_font_main, fontSize: 13.sp, maxLines: 0);
      SilText valueWidget = SilText("${itemValues[i]}℃",
          color: ColorUtils.color_theme,//ColorUtils.hexColor("#28A745"), 
          fontSize: 13.sp, maxLines: 0);
      itemWidgets.add(Expanded(
          child: SilTextIconButton(
        titleWidget,
        valueWidget,
        space: 6.w,
        imagePosition: ImagePosition.Down,
      )));
    }

    return Container(
      margin: EdgeInsets.only(top: 25.w),
      child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: itemWidgets),
    );
  }
}
